package edu.uoc.practica.bd.uocbugdb.exercise1;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.util.List;

import edu.uoc.practica.bd.util.DBAccessor;
import edu.uoc.practica.bd.util.FileUtilities;

public class Exercise1UpdateDataFromFile {
	private FileUtilities fileUtilities;

	public Exercise1UpdateDataFromFile() {
		super();
		fileUtilities = new FileUtilities();
	}

	public static void main(String[] args) {
		Exercise1UpdateDataFromFile app = new Exercise1UpdateDataFromFile();
		app.run();
	}

	private void run() {
		List<List<String>> fileContents = null;
		try {
			fileContents = fileUtilities
					.readFileFromClasspath("exercise1.data");
		} catch (FileNotFoundException e) {
			System.err.println("ERROR: File not found");
			e.printStackTrace();
		} catch (IOException e) {
			System.err.println("ERROR: I/O error");
			e.printStackTrace();
		}
		if (fileContents == null) {
			return;
		}

		DBAccessor dbaccessor = new DBAccessor();
		dbaccessor.init();
		Connection conn = dbaccessor.getConnection();

		// TODO Prepare everything before inserting

		for (List<String> row : fileContents) {
			// TODO Insert record into issue_log for every row in file
		}

		// TODO Validate transaction

		// TODO Close resources and check exceptions
	}
}
